function getQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}
layui.use('table', function(){
  var table = layui.table;
  var delurl = "/general/erp5/public/tripapi/plan/Delete";
  //方法级渲染
  table.render({
    elem: '#apply_list'
    ,url: '/general/erp5/public/tripapi/plan/GetAllListForManager'
    ,request: {
      page: 'page',   // 页码的参数名称，默认：page
      limit: 'limit'   // 每页数据量的参数名，默认：limit
    }
    ,response: {
        statusName: 'status'
        ,statusCode: 200
        ,msgName: 'msg'
        ,countName: 'count'
        ,dataName: 'data'
      }
    ,cols: [[
       {checkbox: true, fixed: true}
      ,{field:'id', title: 'ID',width:70,align:'center'}
      ,{field:'plan_num', title: '计划单号',width: 150,align:'center'}
      ,{field:'status1', title: '审批状态',width: 300,align:'center',templet:setState}
      ,{field:'department', title: '部门名称',width: 140,align:'center'}
      ,{field:'user_name', title: '填报人姓名',width: 140,align:'center'}
      ,{field:'total_day', title: '天数总和',width: 125,align:'center'}
      ,{field:'traffic_money', title: '交通费总和', width: 125,align:'center'}
      ,{field:'hotel_money', title: '住宿费总和',width: 125,align:'center'}
      ,{field:'meal_money', title: '餐饮费总和',width: 125,align:'center'}
      ,{field:'total_money', title: '费用总和',width: 125,align:'center'}
      ,{field:'create_time', title: '创建时间',width: 140,align:'center'}
    ]]
    ,id: 'testReload'
    ,page: true
    ,toolbar:"#tab2Bar"
    ,text: { none: '暂无相关数据' }
  });
  function setState(data){
      if(data.to_status_step == "0" && data.to_status_step1 == '0'){
        return "<span style = 'color: red'>员工提交 - 部门经理审批中</span>";
      }else if(data.to_status_step == "1" && data.to_status_step1 == '0'){
        return "<span style = 'color: green'>员工提交 - 部门经理审批完成 - 流转至总经理</span>";
      }else{
        return "<span style = 'color: green'>部门经理提交 - 流转至总经理</span>";
      }
  }

  table.on('toolbar(user)', function (obj) {
    switch(obj.event){
      case 'show':
        location.replace("/general/erp5/public/tripapi/plan/add");
        break;
    }

  })
  $("#reloadBtn").click(function (ev) {
    console.info("reload");
    var department = $("#department").val();
    var approve_people = $("#approve_people").val();
    var travel_people = $("#travel_people").val();
    table.reload('testReload', {
      url: '/general/erp5/public/tripapi/plan/SearchResult'
      , where: {
        department: department,
        approve_people: approve_people,
        travel_people: travel_people
      }

    });

  })

  $('.apply_table .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});